package apig.server;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;

import apii.algorithm.Algorithm;
import apii.algorithm.colmo.ColmogorovDiffAlgo;
import apii.algorithm.fingerprints.FingerprintsAlgorithm;

/**
 * <b>Note:</b> Thread SAFE.
 * <p>
 * <b>Note:</b> Creates threads.
 * 
 * UNDER CONSTRUCTION
 * 
 * @author evgeniy
 * 
 */
public class AlgoRunManager2 {
	private static final List<Algorithm> ALGOS = Arrays.asList(new Algorithm[] {
			new FingerprintsAlgorithm(), new ColmogorovDiffAlgo() });

	private AlgoRunManager2() throws SQLException {
		runFirst();
	}

	public boolean runCodeLabour(int codeId) throws SQLException {
		return false;
	}

	public double getCodeProgress(int codeId) {
		return 0;
	}

	private static AlgoRunManager2 instance;

	public static final synchronized AlgoRunManager2 getManager()
			throws SQLException {
		if (instance == null)
			instance = new AlgoRunManager2();
		return instance;
	}

	private void runFirst() throws SQLException {
		try (Connection c = ServerThings.getThings().getConnection();
				Statement s = c.createStatement();) {
			ResultSet rs = s
					.executeQuery("select code_id from codes where checked = false");
			while (rs.next())
				runCodeLabour0(rs.getInt(1));
		}
	}

	private void runCodeLabour0(int codeId) throws SQLException {
	}
}
